/**
 ****************************************************************************************************
 * @file        DRI_Init.c
 * @author      LXP
 * @version     V1.0
 * @date        2024-08-13
 * @brief       驱动层所有驱动初始化代码
 *
 ****************************************************************************************************
 */

#include "DRI_Init.h"

//外部引用TOUCH结构数据
extern atk_rgblcd_touch_point_t point[2];



/**
 * @brief       驱动层总初始化文件
 * @param       无
 * @retval      无
 */
Enum_InitStatus DRI_Init()
{
	Enum_InitStatus retValue = init_OK;
	//延时函数初始化，系统时钟168M，低于1毫秒延时用
	delay_init(168);
	//SDRAM初始化
	sdram_init();
	//LCD初始化
	lcd_init();
	//NAND FLASH初始化
	if(nand_init() != 0)
	{
		retValue |= init_Nand_Err;
	}
	//电容触摸初始化
	if(touch_GT11_init(ATK_RGBLCD_TOUCH_TYPE_GTXX) == ATK_RGBLCD_TOUCH_ERROR)
	{
		retValue |= init_Touch_Err;
	}
	//3路串口初始化
	usart_init();
	//RTC初始化
	rtc_init();
	return retValue;
}
//仅做测试用，正式版注释掉大括号中内容
extern UART_HandleTypeDef huart4;
extern DMA_HandleTypeDef hdma_uart4_tx;
uint8_t Tx_Array1[]="UART4 SEND OK1!";
uint8_t Tx_Array2[]="UART4 SEND OK2!";
volatile uint8_t Tx_Array[50];
uint8_t Rx_Array[255]="UART4 SEND OK2!";
volatile uint8_t rx_datNum=15;
extern DMA_HandleTypeDef hdma_uart4_rx;

void DRI_Test()
{
	uint8_t tmp;
	Time_TypeDef time_Structure;
	uint8_t dispArray[20];

	uint16_t xx,yy;
//	while(1)
	{
		rtc_getDataTime(&time_Structure);
		sprintf((char *)dispArray,"Y-M-D:%02d-%02d-%02d",time_Structure.year,time_Structure.month,time_Structure.day);
		lcd_show_string(100, 100, 240, 32, 32, (char *)dispArray, RED);
		sprintf((char *)dispArray,"H-M-S:%02d-%02d-%02d",time_Structure.hour,time_Structure.min,time_Structure.sec);
		lcd_show_string(100, 150, 240, 32, 32, (char *)dispArray, RED);
		HAL_Delay(1000);
	}
	HAL_UART_Transmit_DMA(&huart4, Tx_Array1, 15);
	HAL_UART_Receive_DMA(&huart4, Rx_Array, 50);
//	HAL_UART_Transmit_DMA(&huart4, Tx_Array2, 15);
	tmp = 255-__HAL_DMA_GET_COUNTER(&hdma_uart4_rx);
while(1)
{

	if(rx_datNum > 0)
	{
		HAL_UART_Transmit_DMA(&huart4, Rx_Array, tmp);
		rx_datNum=0;
		HAL_UART_Receive_DMA(&huart4, Rx_Array, 255);
	}
}


	while(1);
	xx=0;
	yy=0;
	while(1)
	{
		//如果获取到触摸显示出来
		if(atk_rgblcd_touch_scan(point, 1) != 0)
		{
			lcd_fill_circle(xx, yy, 5, WHITE);
			lcd_fill_circle(point[0].x, point[0].y, 5, RED);
			xx = point[0].x;
			yy = point[0].y;
			BUZ_openTime(20);
			HAL_Delay(300);
			atk_rgblcd_touch_scan(point, 1);
		}
	}
}



